package juice.AOP$introduction;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class LoggerMethodInterceptor implements MethodInterceptor
{

	@Override
	public Object invoke(MethodInvocation arg0) throws Throwable
	{
		String methodName = arg0.getMethod().getName();
		long starttime = System.nanoTime();
		System.out.println(String.format("before method [%s] at %s", methodName, starttime));
		Object ref;
		try
		{
			ref = arg0.proceed();
		}
		finally
		{
			long endtime = System.nanoTime();
			System.out.println(String.format("after method [%s] at %s cost[na]:%s", methodName, endtime, (endtime - starttime)));
		}
		return ref;
	}

}
